<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>修改程序步骤资源</title>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
    <link href="../../../webjar/bootstrap/3.3.7-1/css/bootstrap.min.css" rel="stylesheet">
    <link href="../../../webjar/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="../../../webjar/css/mystyle.css" rel="stylesheet">

    <script type="text/javascript" charset="utf-8" src="../../../webjar/jquery/3.1.1/jquery.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="../../../webjar/bootstrap-table/bootstrap-table.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="../../../webjar/layer/layer.js"></script>
    <script type="text/javascript" charset="utf-8" src="../../../webjar/plugins/layui/layui.js"></script>
    <script type="text/javascript" charset="utf-8" src="../../Public/ServerPath.js"></script>
    <script type="text/javascript" charset="utf-8" src="../../Public/Sign.js"></script>
    <script type="text/javascript" charset="utf-8" src="../../Public/ibcpLayer.js"></script>
    <script type="text/javascript" charset="utf-8" src="../../Public/ibcpAjax.js"></script>
    
    <script type="text/javascript" charset="utf-8" src="ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="ueditor.all.js"> </script>    
    <script type="text/javascript" charset="utf-8" src="util.js"> </script>    
    <!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
    <!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
    <script type="text/javascript" charset="utf-8" src="lang/zh-cn/zh-cn.js"></script>
	<script type="text/javascript" charset="utf-8" src="btn_add/addBtnDialog.js"> </script>
	<script type="text/javascript" charset="utf-8" src="hr_add/addHrDialog.js"> </script>
	<script type="text/javascript" charset="utf-8" src="customizedBorder/customizedBorder.js"> </script>
    <style type="text/css">
        div{
            width:100%;
        }
        #edui7_toolbarbox {
            margin-bottom: 10px;
        }
    </style>
	<script>
	/*UE.commands["customizedBorder"] = {
        queryCommandState: function () {
			console.log(this);
            return getSelectedArr(this).length > 1 ? 0 : -1;
        },
        execCommand: function (cmd, value) {
            var cells, ut;
            cells = getSelectedArr(this);
            ut = getUETable(cells[0]);
            ut.setBackground(cells, value);
        }
    };*/
	</script>
</head>
<body style="padding-left:5px;">
    <div>
        <script id="editor" type="text/plain" style="width:770px;height:auto;margin-bottom:8px;"></script>
        <script>
            var Height = $(window).height() * 0.97;
            $('#editor').css('height',Height*0.57);
        </script>
    </div>
    <div style="width:720px;margin:20px 0;position:relative;top:0;left:0">
        <div style="width:100px;position:absolute;top:0;left:10%;">
            <button id="btnEditConfirm" type="button" class="btn btn-custom" onclick="proStepSrcEdit()">确认</button>
        </div>
        <div style="width:100px;position:absolute;top:0;left:90%;">
            <button id="btnEditCancel" type="button" class="btn btn-custom" onclick="proStepSrcCancel()">取消</button>
        </div>
    </div>
    <!-- 弹出层定义 -->
    <div id="SignDiv" hidden="true"></div>
</body>
<script type="text/javascript">
    //实例化编辑器
    //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
    var ue = UE.getEditor('editor');
    ue.ready(function(){
        var css=ue.document.createElement('link');
        css.rel="stylesheet";
        css.type="text/css";
        css.href="../../../webjar/bootstrap/3.3.7-1/css/bootstrap.min.css";
        ue.document.head.getElementsByTagName('link')[0].prepend(css);
        ue.document.body.style.margin='0px';
        ue.document.body.style.padding='0px';
        ue.document.body.style.paddingLeft='25px';
        ue.document.body.style.paddingRight='25px';
        ue.document.body.style.paddingRight='25px';
    });

    var proDetailUrl = serverPath + 'craftProcessSteps/findCraftProcessStepDetail';
    var proStepSrclUrl = serverPath + 'craftProcessSteps/updateCraftProcessStepResource';

    var index = parent.layer.getFrameIndex(window.name);

    //根据名称获取Url中某个参数的值
    function GetUrlParam(pname) {
        var reg = new RegExp("(^|&)" + pname + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return decodeURI(r[2]);
        return null;
    }

    $(function() {
        var proStepId = GetUrlParam('id');
        var datas = {'id':proStepId};
        ibcpAjax.Select(proDetailUrl,datas,true,function(result) {
            var data = result.data;
            var resource = data["resource"];
            UE.getEditor('editor').execCommand('insertHtml', resource);
        });
    });

    // 修改程序步骤资源确定按钮事件
    function proStepSrcEdit() {
        var editSrc = UE.getEditor('editor').getContent();
        var proStepId = GetUrlParam('id');
        signPath = '../../Public/';
        //签名
        CallSign(100,function(sid) {
            var proStepId = GetUrlParam('id');
            var datas = {'sid':sid,'resource':editSrc,'id':proStepId};
            ibcpAjax.Update(proStepSrclUrl,datas,true,function() {
                ibcpLayer.ShowOK('修改成功');
                // 签名层消失
                SignCancel();
                // 关闭iframe
                proStepSrcCancel();
                // 获取新数据
                window.parent.GetproStepPic(proStepId);
            });
        });
    };

    //升级程序步骤 取消按钮事件
    function proStepSrcCancel(){
        parent.layer.close(index);
    }

    function isFocus(e){
        alert(UE.getEditor('editor').isFocus());
        UE.dom.domUtils.preventDefault(e)
    }
    function setblur(e){
        UE.getEditor('editor').blur();
        UE.dom.domUtils.preventDefault(e)
    }
    function insertHtml() {
        var value = prompt('插入html代码', '');
        UE.getEditor('editor').execCommand('insertHtml', value)
    }
    function createEditor() {
        enableBtn();
        UE.getEditor('editor');
    }
    function getAllHtml() {
        alert(UE.getEditor('editor').getAllHtml())
    }
    function getContent() {
        var arr = [];
        arr.push("使用editor.getContent()方法可以获得编辑器的内容");
        arr.push("内容为：");
        arr.push(UE.getEditor('editor').getContent());
        alert(arr.join("\n"));
    }
    function getPlainTxt() {
        var arr = [];
        arr.push("使用editor.getPlainTxt()方法可以获得编辑器的带格式的纯文本内容");
        arr.push("内容为：");
        arr.push(UE.getEditor('editor').getPlainTxt());
        alert(arr.join('\n'))
    }
    function setContent(isAppendTo) {
        var arr = [];
        arr.push("使用editor.setContent('欢迎使用ueditor')方法可以设置编辑器的内容");
        UE.getEditor('editor').setContent('欢迎使用ueditor', isAppendTo);
        alert(arr.join("\n"));
    }
    function setDisabled() {
        UE.getEditor('editor').setDisabled('fullscreen');
        disableBtn("enable");
    }

    function setEnabled() {
        UE.getEditor('editor').setEnabled();
        enableBtn();
    }

    function getText() {
        //当你点击按钮时编辑区域已经失去了焦点，如果直接用getText将不会得到内容，所以要在选回来，然后取得内容
        var range = UE.getEditor('editor').selection.getRange();
        range.select();
        var txt = UE.getEditor('editor').selection.getText();
        alert(txt)
    }

    function getContentTxt() {
        var arr = [];
        arr.push("使用editor.getContentTxt()方法可以获得编辑器的纯文本内容");
        arr.push("编辑器的纯文本内容为：");
        arr.push(UE.getEditor('editor').getContentTxt());
        alert(arr.join("\n"));
    }
    function hasContent() {
        var arr = [];
        arr.push("使用editor.hasContents()方法判断编辑器里是否有内容");
        arr.push("判断结果为：");
        arr.push(UE.getEditor('editor').hasContents());
        alert(arr.join("\n"));
    }
    function setFocus() {
        UE.getEditor('editor').focus();
    }
    function deleteEditor() {
        disableBtn();
        UE.getEditor('editor').destroy();
    }
    function disableBtn(str) {
        var div = document.getElementById('btns');
        var btns = UE.dom.domUtils.getElementsByTagName(div, "button");
        for (var i = 0, btn; btn = btns[i++];) {
            if (btn.id == str) {
                UE.dom.domUtils.removeAttributes(btn, ["disabled"]);
            } else {
                btn.setAttribute("disabled", "true");
            }
        }
    }
    function enableBtn() {
        var div = document.getElementById('btns');
        var btns = UE.dom.domUtils.getElementsByTagName(div, "button");
        for (var i = 0, btn; btn = btns[i++];) {
            UE.dom.domUtils.removeAttributes(btn, ["disabled"]);
        }
    }

    function getLocalData () {
        alert(UE.getEditor('editor').execCommand( "getlocaldata" ));
    }

    function clearLocalData () {
        UE.getEditor('editor').execCommand( "clearlocaldata" );
        alert("已清空草稿箱")
    }

    /*画面关闭事件*/
    function initUnloadEvent(){
        'use strict';
        layer.confirm('是否在关闭前进行保存？', {
            title: '提示',
            zIndex: layer.zIndex,
            btn: ['保存', '关闭'],
            yes: function (index) {
                proStepSrcEdit();
            },
            btn2: function(index){
                var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                parent.layer.close(index);
            }
        });
    }

    /*判断是否保存*/
    function savedCheck(){
        'use strict';
        var editSrc = UE.getEditor('editor').getContent();      //获取当前程序步骤编辑器中的内容
        var proStepId = GetUrlParam('id');                      //获取url传递过来的程序步骤id
        var precon;
        var datas = {
            "id":proStepId,
        }
        ibcpAjax.Select(proDetailUrl,datas,true,function(result) {
            precon = result.data.resource;
        });
        if (precon == editSrc) {
            return(false);					//不需要保存
        }else{
            return(true);					//需要保存
        }
    }
</script>
</html>